<?php
	include("configuracion.php");
	
function convertArrayKeysToUtf8(array $array) { 
    $convertedArray = array(); 
	
    foreach($array as $key => $value) { 
      if(!mb_check_encoding($key, 'UTF-8')) $key = utf8_encode($key); 
      if(is_array($value)) $value = convertArrayKeysToUtf8($value); 

      $convertedArray[$key] = $value; 
    }
	
    return $convertedArray; 
  } 
	
	
	
	
	
	$campos = $_GET['campo'];
	$tablas = $_GET['tabla'];
	(isset($_GET['condicion']))? $where=" where ".$_GET['condicion']:$where=NULL;
	(isset($_GET['ordernar']))? $orderBy=" order by ".$_GET['ordernar']:$orderBy=NULL;
	
	if (is_null($campos)){
		break;
	}
	
	
	$conexion = new mysqli($config_servidor_bd, $config_usuario_bd, $config_password_bd, $config_baseDatos_bd);
	
	
	$sql = "SELECT ".$campos." FROM `".$tablas."`".$where.$orderBy;
	
	$conexion = new mysqli($config_servidor_bd, $config_usuario_bd, $config_password_bd, $config_baseDatos_bd);
	
	
	$resulset = $conexion->query($sql);
	
	$arr = array();
	$i=0;
	
	while($fila=$resulset->fetch_assoc()){
		//$arr[] = utf8_encode($fila);
		$arr[] = $fila;
	}
	
	convertArrayKeysToUtf8($arr);
	//print_r($arr);
	echo '' . json_encode($arr) . '';

?>